import ApiConfig from '../api-config'
const img_url = ApiConfig.oss_img;
export let price = function (value) {
    return '$'+parseFloat(value).toFixed(2)
};
const imgFilter=ApiConfig.img_dir;
export let name_to_dir = function (value) {
    var alia = value.trim().match(/\w+?_(?=\d)/g)&&value.trim().match(/\w+?_(?=\d)/g)[0];
    if(alia){
        if(imgFilter[alia.replace(/_$/,'')]){
            return alia.replace(/_$/,'');
        }else{
            return false;
        }
    }else {
        return false
    }
};export let img_whq = function (value) {
    if(value){
        var alia = value.trim().match(/\w+?_(?=\w)/g)&&value.trim().match(/\w+?_(?=\w)/g)[0];
        if(alia){
            if(imgFilter[alia.replace(/_$/,'')]){
                return img_url + imgFilter[alia.replace(/_$/,'')] + value;
            }else{
                return false;
            }
        }else {
            return false
        }
    }
};
export let img_url_wh = function (value,w,h) {
    var u = img_whq(value);
    if(u){
        u = u+'?x-oss-process=image/resize,m_fill,limit_0,w_'+w+',h_'+h;//固定宽高，将延伸出指定w与h的矩形框外的最小图片进行居中裁剪。
        return u;
    }else{
        return false
    }
};